/*
 * lib2Desa - Another 2D game library in C++
 * Copyright (C) 2009 Erivaldo Xavier de Lima Filho
 *
 * This program is free software and is distributed under GNU General Public License version 3. You can modify and/or redistribute
 * it under the terms of GPL version 3 or posterior version. This program comes with NO WARRANTY, for more details, see LICENSE,
 * or <http://www.gnu.org/licenses>.
 *
 * Contact info:
 *
 *	Erivaldo Xavier de Lima Filho, desadoc@gmail.com
 *
 */

#include "Core/GeomUtil.hpp"

#ifndef _NO_NAMESPACE
namespace lib2Desa {
#endif

Rect collision(const Rect& a, const Rect& b)
{
	if((a.x() + a.w()) <= b.x()) return Rect();
	if((b.x() + b.w()) <= a.x()) return Rect();

	if((a.y() + a.h()) <= b.y()) return Rect();
	if((b.y() + b.h()) <= a.y()) return Rect();

	bool _b;
	float x, y, w, h;

	_b = (a.x()>b.x());

	x = (_b)?a.x():b.x();
	w = (_b)?(b.x() + b.w() - a.x()):(a.x() + a.w() - b.x());

	_b = (a.y()>b.y());

	y = (_b)?a.y():b.y();
	h = (_b)?((b.y() + b.h()) - a.y()):((a.y() + a.h()) - b.y());

	return Rect(vector<2,float>(x,y), vector<2,float>(w,h));
}

#ifndef _NO_NAMESPACE
}
#endif
